package com.huanuo.internetofthings.config;

import com.google.common.collect.Maps;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.unicorn.framework.shiro.config.ShiroDefaultConfiguration;
import org.unicorn.framework.util.http.CoreHttpUtils;
import org.unicorn.framework.util.json.JsonUtils;

import java.util.LinkedHashMap;
import java.util.Map;

@Configuration
public class ShiroConfiguration extends ShiroDefaultConfiguration {
	@Autowired
	AuthorizingRealm userAuthRealm;
	@Override
	public void loadShiroFilterChain(ShiroFilterFactoryBean shiroFilterFactoryBean) {
		Map<String, String> filterChainDefinitionMap = new LinkedHashMap<String, String>();
		filterChainDefinitionMap.put("/verificationCode", "anon");
		shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
	}

	@Override
	public AuthorizingRealm getAuthorizingRealm() {
		userAuthRealm.setCredentialsMatcher(hashedCredentialsMatcher());
		return userAuthRealm;
	}

	public static void main(String [] args) throws Exception{
		Map<String,String> headMap= Maps.newConcurrentMap();
		headMap.put("iot-token","0E07EB147E91E1B62F06463310566025");
		System.out.println(JsonUtils.toJson(CoreHttpUtils.get("http://127.0.0.1:8001/iotSysUser/info",headMap)));

	}
}
